<?php

if (isset($_POST['login_as'])) {
	$user = $db->fetchRow("SELECT * FROM cms_users WHERE site_id=? AND (username=? OR email=?)", array($site['id'], $_POST['login_as']['username_or_email'], $_POST['login_as']['username_or_email']));

	$user['custom_fields'] = $db->fetchRow("SELECT * FROM cms_users_custom_{$site['id']} WHERE user_id=?", $user['id']);
	$user['access_rights'] = unserialize($user['access_rights']);
	$_SESSION['login'] = array('user' => $user, 'timestamp' => time());
	$login_succeeded = true;
	unset($user);


	header('Location: /admin/');

}

$smarty->display('loginas.tpl.html');

